package com.cheneyjoo.usecase;

import com.cheneyjoo.model.SYS_USER;
import com.cheneyjoo.service.ISysUserService;
import com.cheneyjoo.tools.DruidUtils;
import com.cheneyjoo.tools.Md5Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class SysUserUseCase implements ISysUserService {
    @Override
    public SYS_USER login(String userName,String password) {
        QueryRunner qr=null;
        try {
            qr = new QueryRunner(DruidUtils.DATASOURCE);
            String sql="select * from SYS_USER where USER_NAME=?";
            SYS_USER query = qr.query(sql, new BeanHandler<SYS_USER>(SYS_USER.class), userName);
            String entryPass= Md5Utils.encrypt(password);
            if(entryPass.equalsIgnoreCase(query.getPassword())){
                return query;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
